﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE A_GET_JornadasByUser
	-- Add the parameters for the stored procedure here
	@IDUtilizador AS INT
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	DECLARE @IDCampeonato AS INT
	SELECT @IDCampeonato = IDCampeonato FROM A_RegistoCampeonatos WHERE IDUtilizador = @IDUtilizador
	AND Activo = 'S'
	
	SELECT DISTINCT J.IDJornada, J.Descricao FROM A_Jornada J
	INNER JOIN A_Jogos JG ON J.IDJornada = JG.IDJornada
	WHERE JG.IDCampeonato = @IDCampeonato	
	ORDER BY J.IDJornada ASC
	
END